package com.byref.liteflowdemo.controller;

import com.byref.liteflowdemo.cmp.decleardemo.MyContext;
import com.byref.liteflowdemo.cmp.decleardemo.UserInfo;
import com.yomahub.liteflow.core.FlowExecutor;
import com.yomahub.liteflow.flow.LiteflowResponse;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author BYREF
 */
@RestController
@RequestMapping("/test")
@Slf4j
@Tag(name = "测试接口")
@RequiredArgsConstructor
public class TestController {
    @SuppressWarnings("SpringJavaInjectionPointsAutowiringInspection")
    private final FlowExecutor flowExecutor;

    @GetMapping("ping")
    @Operation(summary = "测试接口")
    public String ping() {
        return "pong";
    }

    @GetMapping("declare")
    @Operation(summary = "declare测试")
    public String declareTest() {
        MyContext myContext = new MyContext();
        UserInfo userInfo = new UserInfo();
        userInfo.setVip(true);
        myContext.setUser(userInfo);
        LiteflowResponse response = flowExecutor.execute2Resp("declareChain", null, myContext);
        return  myContext.getCoupon();
    }
}
